import { Route } from '@/types';
import got from '@/utils/got';

export const route: Route = {
    path: '/crowdfunding',
    categories: ['shopping'],
    example: '/mi/crowdfunding',
    name: '小米众筹',
    maintainers: ['DIYgod'],
    handler,
};

async function handler() {
    const response = await got({
        method: 'post',
        url: 'http://api.m.mi.com/v1/microwd/home',
        headers: {
            'Mishop-Client-Id': '180100031055',
            'User-Agent': 'MiShop/4.3.68 (iPhone; iOS 12.0.1; Scale/3.00)',
            'IOS-App-Version': '4.3.68',
            'IOS-Version': 'system=12.0.1&device=iPhone10,3',
        },
    });
    const list = response.data.data.list.flatMap((a) => a.items || []);

    return {
        title: '小米众筹',
        link: '',
        allowEmpty: true,
        item:
            list &&
            list.map((item) => ({
                title: item.product_name,
                description: `<img src="${item.img_url}"><br>价格：${item.product_price}元`,
            })),
    };
}
